﻿ (function (window, undefined, $) { 
    $(document).ready(function () { 
        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'ID', width: "4%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: '登陆时间', name: 'LoginTime', width: "7%", sortable: false, align: 'left' },
                    { display: 'MemberID', name: 'MemberID', width: "5%", sortable: false, align: 'left' },
                    { display: 'MemberName', name: 'MemberName', width: "5%", sortable: false, align: 'left' }, 
                    { display: 'IP', name: 'IP', width: "4%", sortable: false, align: 'left', process: formatSex },
                    { display: 'Status', name: 'Status', width: "5%", sortable: false, align: 'left' },
                    { display: 'Remark', name: 'Remark', width: "5%", sortable: false, align: 'left', process: formatMarital }, 
                    { display: '操作', name: 'ID', width: "20%", sortable: false, align: 'center', process: processOp } 
            ],
            sortname: "Id",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
            ops.push("&nbsp;&nbsp;<a title='跟进' class='abtn' href='javascript:;'  onclick=\"util.FollowUp('", value, "')\"><i class='fa fa-edit' ></i>跟进</a>");
            //ops.push("&nbsp;&nbsp;<a title=' 邮箱认证' class='abtn' href='javascript:;'  onclick=\"util.CertifiedMail('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' >邮箱认证</i></a>");
            //ops.push("&nbsp;&nbsp;<a title=' 修改密码' class='abtn' href='javascript:;'  onclick=\"util.Auth('", value, "')\"><i class='fa fa-trash-o' ></i>修改密码</a>");

            return ops.join("");
        }
        function processInput(value, cell) {
            var ops = [];
            ops.push("<input id=\"Checkbox1\" type=\"checkbox\" value=\"", value, "\" />");
            //ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            //ops.push("&nbsp;&nbsp;<a title=' 邮箱认证' class='abtn' href='javascript:;'  onclick=\"util.CertifiedMail('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' >邮箱认证</i></a>");
            //ops.push("&nbsp;&nbsp;<a title=' 修改密码' class='abtn' href='javascript:;'  onclick=\"util.Auth('", value, "')\"><i class='fa fa-trash-o' ></i>修改密码</a>");

            return ops.join("");
        }
        function formatCarcase(value, cell) {
            if (value == 1) {
                return '是';
            }
            else if (value == 2) {
                return '否';
            }
        }
        function formatPurchase(value, cell) {
            if (value == 1) {
                return '是';
            }
            else if (value == 2) {
                return '否';
            }
        }
        function formatSex(value, cell) {
            if (value == 1) {
                return '男';
            }
            else if (value == 2) {
                return '女';
            }
        }
        function formatMarital(value, cell) {
            if (value == 1) {
                return '未婚';
            }
            else if (value == 2) {
                return '已婚';
            }
        }
        function formatIDType(value, cell) {//证件类型
            if (value == 1) {
                return '身份证';
            }
            else if (value == 2) {
                return '护照';
            }
            else if (value == 3) {
                return '军官证';
            }
            else if (value == 4) {
                return '表示港澳台居民来往大陆通行证';
            }
        }
        function formatEducation(value, cell) {
            if (value == 1) {
                return '高中';
            }
            else if (value == 2) {
                return '本科';
            } else if (value == 3) {
                return '硕士';
            } else if (value == 4) {
                return '博士';
            }
        }
        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            location.href = url;
        });
        //$("#btnAssign").click(function (e) {
        //    var url = options.assignUrl;
        //    location.href = url;
        //});
        $("#btnAssign").click(function (e) {
            $.layer({
                type: 2,
                shade: [0.5, '#000'],
                fix: true,
                title: '编辑用户',
                maxmin: false,
                iframe: { src: options.assignUrl },
                area: ['800px', '440px'],
                end: function (index) {
                    //var sss = document.getElementById("id").value;
                    xjgrid.Reload();
                }
            });
        });

        util.Edit = function (id) {
            //var url = options.editUrl + "/" + id;
            var url = options.editUrl + "/" + id;

            location.href = url;
        };

        util.FollowUp = function (id) {
            var url = options.FollowUpUrl + "?U_MemberID=" + id;
            location.href = url;
        }

        util.CertifiedMail = function (id, name) {
            $.layer({
                type: 2,
                shade: [0],
                fix: false,
                title: '邮箱认证',
                maxmin: false,
                iframe: { src: options.CertifiedmailUrl + "?name=" + name },
                area: ['660px', '400px'],
                close: function (index) {
                    //子窗口返回值 layer.getChildFrame('#name', index).val()
                    //layer.msg('您获得了子窗口标记：' + layer.getChildFrame('#name', index).val(), 3, 1);
                },
                end: function (index) {
                    //$('#lbEnterpriseName').html($('#hideEName').val());
                }
            });
        };
        util.Auth = function (id) {
            $.layer({
                type: 2,
                shade: [0],
                fix: false,
                title: '会员密码',
                maxmin: false,
                iframe: { src: options.AuthenticateUrl + "/" + id },
                area: ['660px', '400px'],
                close: function (index) {
                    //子窗口返回值 layer.getChildFrame('#name', index).val()
                    //layer.msg('您获得了子窗口标记：' + layer.getChildFrame('#name', index).val(), 3, 1);
                },
                end: function (index) {
                    //$('#lbEnterpriseName').html($('#hideEName').val());
                }
            });
        };
        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          alert("操作成功！");

                          xjgrid.Reload();
                      }
                      else {
                          alert("操作失败！");
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);